﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using FuelTracker.Models;
using FuelTracker.Services;
using Caliburn.Micro;
using FuelTracker.Resources;

namespace FuelTracker.ViewModels
{
    public class VehiclesViewModel : Screen
    {
        private INavigationService navigationService;
        private IStorageService storageService;
        private ParameterService parameterService;

        private ObservableCollection<VehicleInfo> vehicles = new ObservableCollection<VehicleInfo>();
        public ObservableCollection<VehicleInfo> Vehicles
        {
            get { return vehicles; }
        }

        private VehicleInfo selectedVehicle;
        public VehicleInfo SelectedVehicle
        {
            get { return selectedVehicle; }
            set
            {
                if (selectedVehicle != value)
                {
                    selectedVehicle = value;
                    NotifyOfPropertyChange(() => SelectedVehicle);
                }
            }
        }

        public VehiclesViewModel(INavigationService navigationService, IStorageService storageService, ParameterService parameterService)
        {
            this.navigationService = navigationService;
            this.storageService = storageService;
            this.parameterService = parameterService;
        }

        protected override void OnActivate()
        {
            base.OnActivate();

            vehicles.Clear();
            foreach (VehicleInfo vehicle in storageService.VehicleInfos)
            {
                vehicles.Add(vehicle);
            }
        }

        public void AddNewVehicle()
        {
            navigationService.Navigate(Uris.CreateVehicleView);
        }

        public string PageTitle
        {
            get { return Texts.Lbl_ApplicationTitleAllCaps; }
        }

        public string Title
        {
            get { return Texts.Lbl_Vehicles; }
        }

    }
}
